package com.ideadata.console.flow.action.struts2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;

import org.apache.struts2.ServletActionContext;

import com.ideadata.exception.FlowException;
import com.ideadata.flow.domain.FlowProcessDefinitionVO;
import com.ideadata.flow.service.IGeneralFlowService;
import com.ideadata.flow.service.IManagementFlowService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 工作流
 *
 */
public class FlowAction extends ActionSupport{
	
	/**
	 * @Fields uploadfile : TODO(得到上传的文件)
	 */
	private File uploadfile;// 得到上传的文件
	protected IGeneralFlowService generalflow;
	protected IManagementFlowService managementflow;
	List<FlowProcessDefinitionVO> flowlist;
	
	
	/**
	 * @return 流程模板管理转向
	 * @throws FlowException 
	 */
	public String toFlowTemplateManger() throws FlowException{
		
		
		flowlist = managementflow.ProcessDefinitionQuery();
		return "toFlowTemplateManger";
		
	}
	
	/**
	 * @return 新增流程转向
	 */
	public String toCreateFlow(){
		
		return "toCreateFlow";
		
	}
	
	/**
	 * @return 发布流程
	 * @throws FileNotFoundException 
	 * @throws FlowException 
	 */
	public String createFlow() throws FileNotFoundException, FlowException{
		String flowname = ServletActionContext.getRequest().getParameter("name");
		 InputStream in=new FileInputStream(uploadfile);   
		 managementflow.deploy(flowname, (ZipInputStream) in);
		
		return "createFlow";
		
	}
	
	/**
	 * @return 流程详细信息转向
	 */
	public String toFlowView(){
		
		return "toFlowView";
		
	}
	
	/**
	 * @return 流程实例图转向
	 */
	public String toFlowExampleImg(){
		
		
		return "toFlowExampleImg";
		
	}
	
	/**
	 * @return 查看流程实例转向
	 */
	public String toFlowExample(){
		
		
		return "toFlowExample";
		
	}
	
	
	
	
	
	
	

	public File getUploadfile() {
		return uploadfile;
	}

	public void setUploadfile(File uploadfile) {
		this.uploadfile = uploadfile;
	}

	public List<FlowProcessDefinitionVO> getFlowlist() {
		return flowlist;
	}

	public void setFlowlist(List<FlowProcessDefinitionVO> flowlist) {
		this.flowlist = flowlist;
	}

	public IGeneralFlowService getGeneralflow() {
		return generalflow;
	}

	public void setGeneralflow(IGeneralFlowService generalflow) {
		this.generalflow = generalflow;
	}

	public IManagementFlowService getManagementflow() {
		return managementflow;
	}

	public void setManagementflow(IManagementFlowService managementflow) {
		this.managementflow = managementflow;
	}

	
}
